﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using DevExpress.Xpo;
namespace ChuanPlus.DAO
{
    class ReceiptDAO
    {
        //
        // save receipt to db, update customer as 1 Unit of work
        //
        public static bool save(Receipt receipt)
        {
            Session.DefaultSession.BeginTransaction();
            try
            {
                receipt.SupplierID.SupplierDebt -= receipt.Amount;
                receipt.SupplierID.Save();
                receipt.Save();

                Session.DefaultSession.CommitTransaction();
                return true;
            }
            catch (Exception)
            {
                Session.DefaultSession.RollbackTransaction();
                return false;
            }            
        }
        //
        // create monthly debt report 
        //    
        public static ArrayList GetDebtReport(Supplier supplier, DateTime d)
        {
            return null;
        }
        public List<Receipt> getReceiptVoucher(DateTime FromDate, DateTime ToDate)
        {
            return null;
        }
        public List<Receipt> getReceiptVoucher(DateTime date)
        {
            return null;
        }
        public static List<Receipt> GetReceipts(string status)
        {
            try
            {
                XPQuery<Receipt> receipt = new XPQuery<Receipt>(Session.DefaultSession);
                var list = from r in receipt
                           where r.Status == status
                           select r;
                return new List<Receipt>(list.AsEnumerable<Receipt>());
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
    }
}
